package com.sun.mybatisplus.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auth: syh
 * @Date: 2021/10/22 14:30
 * @Email: 1014170249@qq.com
 * @Desc: 不在能知，而在能行
 * Direct模式相比于Fanout模式多个路由key
 */
@Configuration
public class DirectRabbitMqConfiguration {


    /**
     * 注册Direct模式交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct_exchange",true,false,null);
    }


    /**
     * sms队列
     * @return
     */
    @Bean
    public Queue directSmsQueue(){
        return new Queue("sms_direct.queue",true);
    }

    /**
     * 邮箱队列
     * @return
     */
    @Bean
    public Queue directEmailQueue(){
        return new Queue("email_direct.queue",true);
    }

    /**
     * 短信队列
     * @return
     */
    @Bean
    public Queue directDuanxinQueue(){
        return new Queue("duanxin_direct.queue",true);
    }

    /**
     * 通过路由key进行绑定
     * @return
     */
    @Bean
    public Binding directSmsBinding(){
        return BindingBuilder.bind(directSmsQueue()).to(directExchange()).with("sms");
    }

    /**
     * 通过路由key进行绑定
     * @return
     */
    @Bean
    public Binding directEmailBinding(){
        return BindingBuilder.bind(directEmailQueue()).to(directExchange()).with("email");
    }

    /**
     * 通过路由key进行绑定
     * @return
     */
    @Bean
    public Binding directDuanxinBinding(){
        return BindingBuilder.bind(directDuanxinQueue()).to(directExchange()).with("duanxin");
    }

}
